﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.Annotations;
using SharedGenomics.Workbench.Annotations;

using Rhino.Mocks;

namespace SharedGenomics.Workbench.Tests.Annotations
{
    [TestClass]
    public class StaticAnnotationPlanFactoryTests
    {
        [TestMethod]
        public void ShouldCreatePlan()
        {
            IAnnotationManager manager = MockRepository.GenerateStub<IAnnotationManager>();
            AnnotationKeyDependencyGraphProvider depProvider = MockRepository.GenerateStub<AnnotationKeyDependencyGraphProvider>();

            //create dependency graph
            List<AnnotationKeyDependencyEdge> edges = new List<AnnotationKeyDependencyEdge>
            {
                new AnnotationKeyDependencyEdge(AnnotationKey.SnpName, AnnotationKey.GoogleSearch),
                new AnnotationKeyDependencyEdge(AnnotationKey.SnpName, AnnotationKey.NcbiSummary),
                new AnnotationKeyDependencyEdge(AnnotationKey.NcbiSummary, AnnotationKey.EntrezGeneId),
                new AnnotationKeyDependencyEdge(AnnotationKey.EntrezGeneId, AnnotationKey.PubMedSearch),
            };

            var graph = new AnnotationKeyDependencyGraph(edges);

            depProvider.Stub(dp => dp.GetRequestDependencyGraph()).Return(graph);

            var descriptors = new[] { AnnotationKey.GoogleSearch, AnnotationKey.NcbiSummary, AnnotationKey.PubMedSearch }
                .Select(k => AnnotationDescriptor.GetDescriptorForKey(k)).ToList();
            manager.Stub(m => m.ActiveAnnotationDescriptors).Return(descriptors);

            //test passes if plan is created
            //the correctness of the plan is tested in an integration-style test for annotation plan execution...
            StaticAnnotationPlanFactory factory = new StaticAnnotationPlanFactory(manager, depProvider);
            var plan = factory.CreatePlan();
        }
    }
}
